<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body style="padding:15px;"> 
<form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label">店铺名称</label>
    <div class="layui-input-block">
      <input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="请输入店铺名称" class="layui-input" value="{$vo.name}">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">店铺分类</label>
    <div class="layui-input-block">
      <select name="cid" lay-verify="required">
        <option value=""></option>
        <foreach name="cates" item="item">
        <optgroup label="{$item.title}">
          <!-- <option value="{$item.cid}">{$item.title}</option> -->
          <foreach name="item.sub_cates" item="sub_cate">
          <option value="{$sub_cate.cid}"  <if condition="(isset($vo) && $item.cid == $vo['cid'] && $sub_cate.cid == 0) || (isset($vo) && $sub_cate.cid == $vo['cid'])">selected</if>>{$sub_cate.title}</option>
          </foreach>
        </optgroup>

        </foreach>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">所在地区</label>
    <div class="layui-input-block">
      <select name="city" lay-verify="required">
        <option value=""></option>
        <foreach name="citys" item="city">
        <optgroup label="{$city.name}">
          <foreach name="city.sub_site" item="sub_city">
          <option value="{$sub_city}"  <if condition="isset($vo) && $sub_city == $vo['city']">selected</if>>{$sub_city}</option>
          </foreach>
        </optgroup>

        </foreach>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">店铺地址</label>
    <div class="layui-input-block">
      <input type="text" name="address" lay-verify="address" autocomplete="off" placeholder="请输入店铺地址" class="layui-input" value="{$vo.address}">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">人均消费</label>
    <div class="layui-input-block">
      <input type="number" name="person_money" lay-verify="person_money" autocomplete="off" placeholder="请输入人均消费" class="layui-input" value="{$vo.person_money}">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">营业开始时间</label>
    <div class="layui-input-block">
      <input type="text" id="start_time" name="start_time" lay-verify="start_time" autocomplete="off" placeholder="请输入营业开始时间" class="layui-input" value="{$vo.start_time}">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">营业结束时间</label>
    <div class="layui-input-block">
      <input type="text" id="end_time" name="end_time" lay-verify="end_time" autocomplete="off" placeholder="请输入营业结束时间" class="layui-input" value="{$vo.end_time}">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">店铺logo</label>
    <div class="layui-input-block">
      <div class="layui-upload">
        <button type="button" class="layui-btn layui-btn-danger" id="test1"><i class="layui-icon"></i>上传图片</button>
        <div class="layui-upload-list">
          <img class="layui-upload-img" id="demo1" src="{$vo.logo_url}" style="width: 60px; height: 60px;<if condition="!$vo['logo_url']">display: none;</if>">
          <p id="demoText"></p>
        </div>
      </div>
      <input type="hidden" id="logo_url" name="logo_url" value="{$vo.logo_url}">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">店铺图片</label>
    <div class="layui-input-block">
      <div class="layui-upload">
        <button type="button" class="layui-btn layui-btn-danger" id="test2"><i class="layui-icon"></i>上传图片</button>
        <div id="demo2" class="layui-upload-list">
          <foreach name="vo.pics_list" item="pic">
          <img class="layui-upload-img" src="{$pic}" style="width: 60px; height: 60px;">
          <!-- <p id="demoText"></p> -->
          </foreach>
        </div>
      </div>
      <input type="hidden" id="pics" name="pics" value="{$vo.pics}">
    </div>
  </div>
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">详细介绍</label>
    <div class="layui-input-block">
      <textarea name="content" placeholder="请输入详细介绍" class="layui-textarea">{$vo.content}</textarea>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">联系人</label>
    <div class="layui-input-block">
      <input type="text" name="username" lay-verify="username" autocomplete="off" placeholder="请输入联系人" class="layui-input" value="{$vo.username}">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">联系电话</label>
    <div class="layui-input-block">
      <input type="text" name="tel" lay-verify="tel" autocomplete="off" placeholder="请输入联系电话" class="layui-input" value="{$vo.tel}">
    </div>
  </div>
  
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="*">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
          
<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use(['form','upload','laydate'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,laydate = layui.laydate
  ,$ = layui.jquery
  ,upload = layui.upload;
  
  laydate.render({
    elem: '#start_time',
    type: 'time',
    format: 'HH:mm'
  });
  laydate.render({
    elem: '#end_time',
    type: 'time',
    format: 'HH:mm'
  });
  var uploadInst1 = upload.render({
    elem: '#test1'
    ,url: '{:U("Home/Public/upload")}'
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#demo1').attr('src', result).show(); //图片链接（base64）
      });
    }
    ,done: function(res){
      //如果上传失败
      if(res.err_code > 0){
        return layer.msg('上传失败');
      }else{
        $("#logo_url").val("https://www.58zltc.com/Uploads/"+res.file_name);
      }
      //上传成功
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });
  var uploadInst2 = upload.render({
    elem: '#test2'
    ,url: '{:U("Home/Public/upload")}'
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#demo2').append('<img class="layui-upload-img layui-nav-img" src="'+result+'" style="width: 60px; height: 60px;">'); //图片链接（base64）
      });
    }
    ,done: function(res){
      //如果上传失败
      if(res.err_code > 0){
        return layer.msg('上传失败');
      }else{
        var pics = $("#pics").val();
        var new_pic = "https://www.58zltc.com/Uploads/"+res.file_name;
        if(pics){
          pics += ','+new_pic;
        }else{
          pics = new_pic;
        }
        $("#pics").val(pics);
      }
      //上传成功
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });
  //监听提交
  form.on('submit(*)', function(data){
    $.post('#', data.field, function(e) {
      var res = e;
      layer.alert(e.info,function(index){
        if(e.status == 1){
          parent.location.reload();
        }
      });
    });
    return false;
  });
  
  
});
</script>

</body>
</html>